﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_banInfo
    {
        private int _id_ban;
        private string _maql;
        private string _tenban;
        private int _stt;
        private int _makv;
        private int _trangthai;

        public cs_erp_banInfo(int id_ban, string maql, string tenban, int stt, int makv, int trangthai)
        {
            this._id_ban = id_ban;
            this._maql = maql;
            this._tenban = tenban;
            this._stt = stt;
            this._makv = makv;
            this._trangthai = trangthai;

        }
        public cs_erp_banInfo()
        {
            this._id_ban = 0;
            this._maql = " ";
            this._tenban = " ";
            this._stt = 0;
            this._makv = 0;
            this._trangthai = 0;

        }
        public int id_ban
        {
            get
            {
                return this._id_ban;
            }
            set
            {
                this._id_ban = value;
            }
        }
        public string maql
        {
            get
            {
                return this._maql;
            }
            set
            {
                this._maql = value;
            }
        }
        public string tenban
        {
            get
            {
                return this._tenban;
            }
            set
            {
                this._tenban = value;
            }
        }
        public int stt
        {
            get
            {
                return this._stt;
            }
            set
            {
                this._stt = value;
            }
        }
        public int makv
        {
            get
            {
                return this._makv;
            }
            set
            {
                this._makv = value;
            }
        }
        public int trangthai
        {
            get
            {
                return this._trangthai;
            }
            set
            {
                this._trangthai = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[7];
            paraName[0] = "@id_ban";
            paraName[1] = "@maql";
            paraName[2] = "@tenban";
            paraName[3] = "@stt";
            paraName[4] = "@makv";
            paraName[5] = "@trangthai";
            paraName[6] = "@option";
            object[] paraValue = new object[7];
            paraValue[0] = this._id_ban;
            paraValue[1] = this._maql;
            paraValue[2] = this._tenban;
            paraValue[3] = this._stt;
            paraValue[4] = this._makv;
            paraValue[5] = this._trangthai;
            paraValue[6] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 7, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_BAN", option);
        }

        
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_BAN", "id_ban = " + this._id_ban);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_ban = Convert.ToInt32(ds.Tables[0].Rows[0]["id_ban"].ToString().Trim());
                this._maql = ds.Tables[0].Rows[0]["maql"].ToString().Trim();
                this._tenban = ds.Tables[0].Rows[0]["tenban"].ToString().Trim();
                this._stt = Convert.ToInt32(ds.Tables[0].Rows[0]["stt"].ToString().Trim());
                this._makv = Convert.ToInt32(ds.Tables[0].Rows[0]["makv"].ToString().Trim());
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_ban, maql, tenban, stt, makv, trangthai"
                + " from ERP_BAN"
                + " where trangthai <> 0 order by makv asc";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_List_banghep()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_ban, maql, tenban, stt, makv, trangthai"
                + " from ERP_BAN"
                + " where trangthai = " + this._trangthai 
                + " and id_ban <> " + this._id_ban
                + " order by makv asc";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public int ThuchienGhepban(int ban)
        {
            string[] paraName = new string[2];
            paraName[0] = "@id_ban";
            paraName[1] = "@banghep";
            
            object[] paraValue = new object[2];
            paraValue[0] = this._id_ban;
            paraValue[1] = ban;
            
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 2, paraValue);
            return csdl.ExcuteStoreProcedure("Proc_ERP_Ghepban");
        }

    }
}
